//
//  NewHomeDataView.m
//  NewPro
//
//  Created by RYX on 2019/4/24.
//  Copyright © 2019 何荧红. All rights reserved.
//

#import "NewHomeDataView.h"
#import "HomeMonsy.h"
#import "HomeList.h"
#import "MyProfitViewController.h"

@interface NewHomeDataView ()

@property (nonatomic,weak) UILabel *syLa;
@property (nonatomic,weak) UILabel *fxLa;
@property (nonatomic,weak) UILabel *frLa;
@property (nonatomic,weak) UILabel *qtLa;

@end

@implementation NewHomeDataView

- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        self.backgroundColor = UIColor.whiteColor;
        [self setUI];
    }
    return self;
}

- (void)setUI{
    
    UIColor *fontColor = [UIColor colorWithHexString:@"333333"];
    
    UIView *line = [[UIView alloc] init];
    line.backgroundColor = UIColor.redColor;
    [self addSubview:line];
    
    UILabel *la2 = [[UILabel alloc] init];
    la2.font = [UIFont systemFontOfSize:14];
    la2.attributedText = [StrTool getAttributedTextWithTitle:@"本月收益" color:[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1.0] fontSize:14];
    [self addSubview:la2];
    
    UIButton *btn = [[UIButton alloc] init];
    [btn setTitle:@"更多" forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont fontWithName:@"PingFang-SC-Medium" size: 12];
    [btn setTitleColor:[UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1.0] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(onMoreBtn:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn];
    
    UILabel *la3 = [[UILabel alloc] init];
    la3.textColor = fontColor;
    la3.font = [UIFont systemFontOfSize:15];
    la3.attributedText = [StrTool getAttributedTextWithTitle:@"收益总额(元)" color:[UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0] fontSize:15];
    [self addSubview:la3];
    
    UILabel *la4 = [[UILabel alloc] init];
    la4.textColor = fontColor;
    la4.font = [UIFont systemFontOfSize:14];
    la4.attributedText = [StrTool getAttributedTextWithTitle:@"返现金额(元)" color:[UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0] fontSize:14];
    [self addSubview:la4];
    
    UILabel *la5 = [[UILabel alloc] init];
    la5.textColor = fontColor;
    la5.font = [UIFont systemFontOfSize:14];
    la5.attributedText = [StrTool getAttributedTextWithTitle:@"分润金额(元)" color:[UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0] fontSize:14];
    [self addSubview:la5];
    
    UILabel *la6 = [[UILabel alloc] init];
    la6.textColor = fontColor;
    la6.font = [UIFont systemFontOfSize:14];
    la6.attributedText = [StrTool getAttributedTextWithTitle:@"其他金额(元)" color:[UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0] fontSize:14];
    [self addSubview:la6];
    
    UIView *line1 = [[UIView alloc] init];
    line1.backgroundColor = BASECOLOR;
    [self addSubview:line1];
    
    UIView *line2 = [[UIView alloc] init];
    line2.backgroundColor = BASECOLOR;
    [self addSubview:line2];
    
    UILabel *syLa = [[UILabel alloc] init];
    self.syLa = syLa;
    syLa.font = [UIFont fontWithName:@"PingFang-SC-Medium" size: 24];
    syLa.textColor = UIColor.redColor;
    syLa.text = @"0.00";
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onMoreBtn:)];
    syLa.userInteractionEnabled = YES;
    [syLa addGestureRecognizer:tap];
    [self addSubview:syLa];
    
    UILabel *fxLa = [[UILabel alloc] init];
    self.fxLa = fxLa;
    fxLa.font = [UIFont fontWithName:@"PingFang-SC-Medium" size: 15];
    fxLa.textColor = fontColor;
    fxLa.text = @"0.00";
    [self addSubview:fxLa];
    
    UILabel *frLa = [[UILabel alloc] init];
    self.frLa = frLa;
    frLa.font = [UIFont fontWithName:@"PingFang-SC-Medium" size: 15];
    frLa.textColor = fontColor;
    frLa.text = @"0.00";
    [self addSubview:frLa];
    
    UILabel *qtLa = [[UILabel alloc] init];
    self.qtLa = qtLa;
    qtLa.font = [UIFont fontWithName:@"PingFang-SC-Medium" size: 15];
    qtLa.textColor = fontColor;
    qtLa.text = @"0.00";
    [self addSubview:qtLa];
    
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.top.equalTo(self).offset(14);
        make.width.mas_equalTo(1.5);
        make.height.mas_equalTo(14);
    }];
    
    [la2 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(line.mas_right).offset(2);
        make.centerY.equalTo(line);
    }];
    
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(self).offset(-14);
        make.centerY.equalTo(line);
    }];
    
    [la3 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self).offset(50);
        make.centerX.equalTo(self);
    }];
    
    [la4 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self).offset(122);
        make.left.equalTo(self).offset(24);
    }];
    
    [la5 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self);
        make.centerY.equalTo(la4);
    }];
    
    [la6 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(self).offset(-24);
        make.centerY.equalTo(la4);
    }];
    
    [syLa mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self);
        make.top.equalTo(la3.mas_bottom).offset(5);
    }];
    
    [fxLa mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(la4);
        make.top.equalTo(la4.mas_bottom).offset(5);
    }];
    
    [frLa mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(la5);
        make.centerY.equalTo(fxLa);
    }];
    
    [qtLa mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(la6);
        make.centerY.equalTo(fxLa);
    }];
    
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.equalTo(la4.mas_right).offset(25);
        make.top.equalTo(la4);
        make.width.mas_equalTo(1);
        make.height.mas_equalTo(34);
    }];

    [line2 mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.equalTo(la5.mas_right).offset(25);
        make.top.equalTo(la5);
        make.width.mas_equalTo(1);
        make.height.mas_equalTo(34);
    }];
}

- (NSMutableAttributedString *)getAttributedTextWithColor:(UIColor *)color size:(CGFloat)size title:(NSString *)title{
    
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:title attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang-SC-Medium" size: size],NSForegroundColorAttributeName: color}];
    
    return string;
}

- (void)setModel:(HomeMonsy *)model{
    
    self.syLa.text = model.syze;
    self.fxLa.text = model.fxje;
    self.frLa.text = model.frje;
    self.qtLa.text = model.qtje;
}

#pragma mark - 更多
- (void)onMoreBtn:(id *)sender{
    
    if (![[HomeList sharedInstance].hadRealName isEqualToString:@"4"]) {
        
        if (self.delegate && [self.delegate respondsToSelector:@selector(judgeIfHadRealName)]) {
            
            [self.delegate judgeIfHadRealName];
            return;
        }
        return;
    }
    
    MyProfitViewController *VC = [[MyProfitViewController alloc] init];
    [VC setHidesBottomBarWhenPushed:YES];
    [[self getCurrentViewController].navigationController pushViewController:VC animated:YES];
}

@end
